package com.lc.luzhengtang.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.lc.luzhengtang.R;
import com.lc.luzhengtang.activity.PhotoShowActivity;
import com.lc.luzhengtang.conn.Conn;
import com.zcx.helper.bound.BoundViewHelper;
import com.zcx.helper.scale.ScaleScreenHelperFactory;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 文 件 名: NewsListAdapter
 * 创 建 人: zhangyu
 * 创建日期: 16/12/24 19:55
 * 邮   箱: yuanchong121@gmail.com
 * 修改时间：
 * 修改备注：
 */
public class ItemPicAdapter2 extends RecyclerView.Adapter<ItemPicAdapter2.ViewHolder> implements View.OnClickListener {
    private final View.OnClickListener onClickListener;
    private Context context;
    private List<String> data;

    public ItemPicAdapter2(Context context, List<String> data, View.OnClickListener onClickListener) {
        this.context = context;
        this.data = data;
        this.onClickListener = onClickListener;
    }

    @OnClick({R.id.text_heheda, R.id.img_glide, R.id.layout_img})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.text_heheda:
                break;
            case R.id.img_glide:
                break;
            case R.id.layout_img:
                break;
        }
    }

    @Override
    public void onClick(View v) {

    }


    // Provide a reference to the views for each data item
    // Complex data items may need more than one view per item, and
    // you provide access to all the views for a data item in a view holder
    public static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.text_heheda)
        TextView textHeheda;
        @BindView(R.id.img_glide)
        ImageView imgGlide;
        @BindView(R.id.layout_img)
        LinearLayout layoutImg;


        public ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

    @Override
    public ItemPicAdapter2.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
       /* View view = BoundViewHelper.boundView(this, MyApplication.scaleScreenHelper.loadView((ViewGroup) LayoutInflater.from(parent.getContext())
                .inflate(R.layout.list_02_item_view, null)));*/
        View view = BoundViewHelper.boundView(this, ScaleScreenHelperFactory.getInstance().loadView((ViewGroup) LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_pic, null)));
        ItemPicAdapter2.ViewHolder vh = new ItemPicAdapter2.ViewHolder(view);
        return vh;
    }


    @Override
    public void onBindViewHolder(ItemPicAdapter2.ViewHolder holder, final int position) {
//        Glide.with(context).load(Conn.HOST2 + list.get(position).getPicarr()).transform(new GlideCircleTransform(context)).error(R.mipmap.touxiang).placeholder(R.mipmap.touxiang).into(holder.imgPerson);
//        Glide.with(context).load(Conn.HOST2 + list.get(position).getPicarr()).transform(new GlideCircleTransform(context)).error(R.mipmap.touxiang).placeholder(R.mipmap.touxiang).into(holder.imgPerson);
        Glide.with(context).load(Conn.HOST3 + data.get(position)).crossFade().error(R.mipmap.zhanwei).placeholder(R.mipmap.zhanwei).into(holder.imgGlide);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.putExtra("position", position);
                intent.putStringArrayListExtra("mImages", (ArrayList<String>) data);
                intent.setClass(context, PhotoShowActivity.class);
                context.startActivity(intent);
            }
        });

    }

    /**
     * Returns the total number of items in the data set hold by the adapter.
     *
     * @return The total number of items in this adapter.
     */
    @Override
    public int getItemCount() {

        return data.size();

    }


}
